package com.onpositive.dataminer.rcp.views;

import com.onpositive.semantic.model.binding.Binding;
import com.onpositive.semantic.ui.workbench.elements.SelectionBinding;
import com.onpositive.semantic.ui.workbench.elements.XMLView;

public abstract class SelectionView extends XMLView {

	Binding m;

	public SelectionView(String id) {
		super(id);
	}

	public SelectionView() {
		super();
	}

	@Override
	protected Binding getBinding() {
		if (m==null){
			m=new SelectionBinding(getViewSite()){
				public void setValue(Object value) {
					if (getTargetClass().isInstance(value)){
						super.setValue(transform(value));
					}
				};
			};
			Binding binding = getSuperBinding();
			binding.setReadOnly(false);
			m.addChild(binding);
		}
		return m;
	}

	protected Binding getSuperBinding() {
		return super.getBinding();
	}
	@Override
	public void dispose() {
		m.dispose();
		super.dispose();
	}

	protected abstract Class getTargetClass();

	protected Object transform(Object value) {
		return value;
	}

}